package controllers;

import play.*;
import play.mvc.*;
import play.data.*;
import java.util.*;
import models.*;

import javax.persistence.Query;
import play.db.jpa.JPA;


/**
 * Manage PUB system.
 */

public class Pub extends Controller {
  
    public static void index() {
        Hospital hospital = Hospital.all().first();
        List<SupervisionList> svList = SupervisionList.findTop();
        
        List<Document> zwDocs = Document.getDocumentsByType("职务公开");
        List<Document> zyDocs = Document.getDocumentsByType("职业公开");
        List<Document> gyDocs = Document.getDocumentsByType("供应商诚信管理");
        List<Document> hzDocs = Document.getDocumentsByType("患者满意度");
        List<Document> dwDocs = Document.getDocumentsByType("党务公开");
        List<Document> ydDocs = Document.getDocumentsByType("医德考评");

        render(hospital, svList, zwDocs, zyDocs, gyDocs, gyDocs, hzDocs, dwDocs, ydDocs );
    }

    public static void index2(long id,  long level2) {
        Hospital hospital = Hospital.all().first();

        List<SupervisionList> svList = SupervisionList.findTop();

        List<SupervisionList> level2List = SupervisionList.findLevel2(id);

        List<Document> documents = null; 
        SupervisionList selectedSV = null;

        if (level2List.size() > 0) {
            if (level2 == 0) {
                selectedSV = level2List.get(0);            
                documents = Document.getDocumentsBySupervision(selectedSV.id);
            } else {
                selectedSV = SupervisionList.findById(level2);
                documents = Document.getDocumentsBySupervision(level2);
            }    
        } else {
            selectedSV = SupervisionList.findById(id);
            documents = Document.getDocumentsBySupervision(id);
        }
        
        render(id, hospital, svList, selectedSV, level2List, documents);
    }

    public static void index3(long id, long docid) {
        Hospital hospital = Hospital.all().first();

        List<SupervisionList> svList = SupervisionList.findTop();

        List<SupervisionList> level2List = SupervisionList.findLevel2(id);

        Document doc = Document.findById(docid);
        
        render(id, hospital, svList, level2List, doc);
    }

    
}

